<?php

     //enroll.php 
     //last edit: made date input boxes into array.  need to create process script and test

     include('./includes/db_connect.php');

    //make sure you have a consumer file
    if($id){
	$title = 'Consumer Program Enrollment';
    } else {
	$title = 'Error! No consumer to enroll.';
    }

    //style counter
    $i = 0;

    //get CIL locations for assignment box
    $query = "SELECT * FROM programs";
 
   
   //set locations to $result
   $programs_result = mysql_query($query);

   //echo "$programs_result";


   //echo "<h1>$id</h1>";

   if($_GET["enrollment"]){
      
      $stored_ir_entry = $_GET["enrollment"];

      //run the query to get stored enrollment record
/*
      $stored_ir_query = "SELECT *
                         FROM irEntry
                         WHERE id = ".$stored_ir_entry.";";

      $result = mysql_query($stored_ir_query);


      if($row = mysql_fetch_array($result)) {

        $date               = $row["date"]; //break this up
        $date_pieces        = explode("-", $date);
        $stored_dateYear    = $date_pieces[0];  //year
        $stored_dateMonth   = $date_pieces[1];  //month
        $stored_dateDay     = $date_pieces[2];  //day

        $irType             = $row["type_id"];
        $stored_sent             = $row["sent"];
        $stored_refer            = $row["refer"];
        $stored_info             = $row["info"];
        $stored_notes          = $row["notes"];
        $stored_entered_by     = $row["entered_by"];

      }
*/
      
   } //end get enrollment


   if(false) {
   } else {
	$dateMonth = date("m", mktime(date("H"),date("i"),date("s"),date("m"), date("d"), date("Y")));
	$dateDay   = date("d", mktime(date("H"),date("i"),date("s"),date("m"), date("d"), date("Y")));
	$dateYear  = date("Y", mktime(date("H"),date("i"),date("s"),date("m"), date("d"), date("Y")));
	$citizen   = 1;
   }
?>


<form action="actions/ProcessEnrollment.php" method="post">

   <div style="border:1px #ddd solid;padding:3px;">
      <h2><?php echo $title ?></h2>
          <p>	
              Enroll this consumer in any direct service program by placing a check in the box
              provided in the Enroll column. To be counted in a program listed below, the 
              consumer must have a completed intake on file.
              <br/><br/>
          </p>

      <table class="table1" id="enrollmentTbl" summary="" style="margin-left: -5px;">
         <caption style="font-size: 14px; color: #B01C1C; padding: 5px; font-weight: bold;">
           List of Current CIL Programs.
         </caption>

           <thead> 
              <tr>
                 <th>Enroll</th>
                 <th>Fiscal Year</th>
                 <th>Program Name</th>
                 <th>Program Description</th>
                 <th>Enrollment Date</th>
                 <th>Unenroll Date</th>
              </tr>
           </thead>
           <tbody>
              <!-- RUN GET PROGRAMS LOOP HERE -->      
<?php
              while($row = mysql_fetch_array($programs_result)) {
                                      
                      $program_id          = $row["program_id"];
                      $program_name        = $row["program_name"];
                      $program_description = $row["program_description"];
                      $program_fiscal_year = $row["fiscal_year"];

                      //echo "<h1>$program_id</h1>";

                      if($i%2==0) {
		 
                          echo "<tr class='even'>";
	
                        }else {
	    
                          echo "<tr class='odd'>";
	      
                        }
?>
           
                     <!-- Enrolled -->
                     <td>
      	
                        <div class="checkBoxUnit">
          
                          <input type="checkbox" name="<?php echo $program_id?>" <?php if($stored_program_id=="1") echo "checked";?>/>
          
                         </div>
                     </td>
                     <td><?php echo $program_fiscal_year ?></td>
                     <td><strong><?php echo $program_name ?></strong></td>
                     <td><?php echo $program_description ?></td>
                     <td>                        
                           <input type="text" name="program_enrollment_date[]" value="<?php echo $stored_program_enrollment_date ?>" style="width:62px;"/>
                     </td>
                     <td>                        
                           <input type="text" name="program_unenroll_date[]" value="<?php echo $stored_program_enroll_date ?>" style="width:62px;"/>
                     </td>
                  </tr>
              
<?php

                  $i++;

              } //end while

?>
              <tr>
    	
                 <td valign="top" colspan="6">
                    <br /><br />
                    <label>Enrollment Notes:</label>
                    <br/><br/>
                    <textarea name="enrollment_notes" cols="115" rows="10">
                        <?php echo $stored_enrollment_notes ?>
                    </textarea>

                 </td>
    
              </tr>


<?php
           if($id) { 

?>
            
             <tr>
             <td colspan="6" align="right">

      	        <input type="hidden" value="<?php echo $id;?>" name="id" />
                <input value="Enroll" class="btn" type="submit">
                <input class="btn" type="button" value="Cancel" onclick="window.location='admin.php?action=cieedit&id=<?php echo $id ?>'"/>
      
             </td>
             </tr>

<?php

           }

?>
    
         </tbody>
       </table>
 
  </div>

</form>